package main

import "fmt"

/*魔术师发牌问题*/
type poke struct {
	data int
	next *poke
}

func newPoke(size int) (header *poke) {
	header = &poke{}
	pre := header
	var now *poke
	for i := 0; i < size - 1; i++ {
		now = &poke{}
		pre.next = now
		pre = now
	}
	pre.next = header
	return pre
}

func (p *poke) faPai() {
	count := 2
	p.data = 1
	for {
		for i := 0; i < count; i++ {
			p = p.next
			if (p.data != 0) {
				i--;
			}
		}

		p.data = count;
		count = count + 1
		if (count == 14) {
			break
		}

	}
}

func (p *poke) print() {
	header := p
	for (p.next != header) {
		fmt.Printf("%d-->", p.data)
		p = p.next
	}
	fmt.Printf("%d\n", p.data)
}
func main() {
	p := newPoke(13)
	p.print()
	p.faPai()
	p.print()

}
